//
//  CSGXCashDetailView.m
//  CarSalesMS_GCX
//
//  Created by Ssky on 2016/12/9.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSGXCashDetailView.h"

#import "TGatheringDayDAL.h"

@interface CSGXCashDetailView ()

@property(nonatomic,weak) UILabel *lblMoneyCommitValue;
@property(nonatomic,weak) UILabel *lblMoneySaleValue;

@end

@implementation CSGXCashDetailView



#pragma mark - setupUI
-(void) setupUI {
    //
    self.backgroundColor = kColorBar;
    
    CGFloat fontSize = 12;
    UIColor *fgColor = [UIColor whiteColor];
    CGFloat margin = 5;
    
#pragma mark col1
    //上缴金额
    UILabel *lblMoneyCommit = [UILabel gx_labelWithText:@"上缴金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyCommit];
    
    lblMoneyCommit.textAlignment = NSTextAlignmentLeft;
    lblMoneyCommit.font = [UIFont boldSystemFontOfSize:fontSize];
    
    [lblMoneyCommit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).mas_offset(2);
        make.leading.equalTo(self).mas_offset(margin);
    }];
    
    //刷卡金额
    UILabel *lblMoneyCard = [UILabel gx_labelWithText:@"刷卡金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyCard];
    
    lblMoneyCard.font = [UIFont boldSystemFontOfSize:fontSize];
    lblMoneyCard.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyCard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCommit.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneyCommit).mas_offset(0);
    }];
    
    //销售金额
    UILabel *lblMoneySale = [UILabel gx_labelWithText:@"销售金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneySale];
    
    lblMoneySale.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneySale mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCard.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneyCard).mas_offset(0);
    }];
    
    //使用余额
    UILabel *lblMoneyBalance = [UILabel gx_labelWithText:@"使用余额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyBalance];
    
    lblMoneyBalance.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyBalance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneySale.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneySale).mas_offset(0);
    }];
    
    //收款金额
    UILabel *lblMoneyGather = [UILabel gx_labelWithText:@"收款金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyGather];
    
    lblMoneyGather.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyGather mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyBalance.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneyBalance).mas_offset(0);
    }];
    
    //退货转预收
    UILabel *lblMoneyReturnToAdvance = [UILabel gx_labelWithText:@"退货转预收" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyReturnToAdvance];
    
    lblMoneyReturnToAdvance.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyReturnToAdvance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyGather.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneyGather).mas_offset(0);
        //last
        make.bottom.equalTo(self).mas_offset(-2);
    }];

#pragma mark col2
    
    //上缴金额 值
    UILabel *lblMoneyCommitValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyCommitValue];
    self.lblMoneyCommitValue = lblMoneyCommitValue;
    
    lblMoneyCommitValue.textAlignment = NSTextAlignmentRight;
    lblMoneyCommitValue.font = [UIFont boldSystemFontOfSize:fontSize];
    
    [lblMoneyCommitValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCommit).mas_offset(0);
        make.trailing.equalTo(self.mas_centerX).mas_offset(-3*margin);
    }];
    
    //刷卡金额 值
    UILabel *lblMoneyCardValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyCardValue];
    
    lblMoneyCardValue.textAlignment = NSTextAlignmentRight;
    
    lblMoneyCardValue.font = [UIFont boldSystemFontOfSize:fontSize];
    
    [lblMoneyCardValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCommitValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneyCommitValue).mas_offset(0);
    }];
    
    //销售金额 值
    UILabel *lblMoneySaleValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneySaleValue];
    self.lblMoneySaleValue = lblMoneySaleValue;
    
    lblMoneySaleValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneySaleValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCardValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneyCardValue).mas_offset(0);
    }];
    
    //使用余额 值
    UILabel *lblMoneyBalanceValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyBalanceValue];
    
    lblMoneyBalanceValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneyBalanceValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneySaleValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneySaleValue).mas_offset(0);
    }];
    
    //收款金额 值
    UILabel *lblMoneyGatherValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyGatherValue];
    
    lblMoneyGatherValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneyGatherValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyBalanceValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneyBalanceValue).mas_offset(0);
    }];
    
    //退货转预收 值
    UILabel *lblMoneyReturnToAdvanceValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyReturnToAdvanceValue];
    
    lblMoneyReturnToAdvanceValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneyReturnToAdvanceValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyGatherValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneyGatherValue).mas_offset(0);
    }];

#pragma mark col3
    
    //应收金额
    UILabel *lblMondyShouldReceive = [UILabel gx_labelWithText:@"应收金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMondyShouldReceive];
    
    lblMondyShouldReceive.textAlignment = NSTextAlignmentLeft;
    
    [lblMondyShouldReceive mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCommit).mas_offset(0);
        make.leading.equalTo(self.mas_centerX).mas_offset(2*margin);
    }];
    
    //刷卡费用
    UILabel *lblMoneyCardFee = [UILabel gx_labelWithText:@"刷卡费用" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyCardFee];
    
    lblMoneyCardFee.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyCardFee mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMondyShouldReceive.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMondyShouldReceive).mas_offset(0);
    }];
    
    //订货金额
    UILabel *lblMoneyOrder = [UILabel gx_labelWithText:@"订货金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyOrder];
    
    lblMoneyOrder.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyOrder mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCardFee.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneyCardFee).mas_offset(0);
    }];
    
    //优惠金额
    UILabel *lblMoneyPreferential = [UILabel gx_labelWithText:@"优惠金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyPreferential];
    
    lblMoneyPreferential.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyPreferential mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyOrder.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneyOrder).mas_offset(0);
    }];
    
    //付款金额
    UILabel *lblMoneyPay = [UILabel gx_labelWithText:@"付款金额" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyPay];
    
    lblMoneyPay.textAlignment = NSTextAlignmentLeft;
    
    [lblMoneyPay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyPreferential.mas_bottom).mas_offset(margin);
        make.leading.equalTo(lblMoneyPreferential).mas_offset(0);
    }];
    

#pragma mark col4
    
    //应收金额 值
    UILabel *lblMondyShouldReceiveValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMondyShouldReceiveValue];
    
    lblMondyShouldReceiveValue.textAlignment = NSTextAlignmentRight;
    
    [lblMondyShouldReceiveValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCommit).mas_offset(0);
        make.trailing.equalTo(self).mas_offset(-margin);
    }];
    
    //刷卡费用 值
    UILabel *lblMoneyCardFeeValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyCardFeeValue];
    
    lblMoneyCardFeeValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneyCardFeeValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMondyShouldReceiveValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMondyShouldReceiveValue).mas_offset(0);
    }];
    
    //订货金额 值
    UILabel *lblMoneyOrderValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyOrderValue];
    
    lblMoneyOrderValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneyOrderValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyCardFeeValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneyCardFeeValue).mas_offset(0);
    }];
    
    //优惠金额 值
    UILabel *lblMoneyPreferentialValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyPreferentialValue];
    
    lblMoneyPreferentialValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneyPreferentialValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyOrderValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneyOrderValue).mas_offset(0);
    }];
    
    //付款金额 值
    UILabel *lblMoneyPayValue = [UILabel gx_labelWithText:@"0.00元" fontSize:fontSize color:fgColor];
    [self addSubview:lblMoneyPayValue];
    
    lblMoneyPayValue.textAlignment = NSTextAlignmentRight;
    
    [lblMoneyPayValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblMoneyPreferentialValue.mas_bottom).mas_offset(margin);
        make.trailing.equalTo(lblMoneyPreferentialValue).mas_offset(0);
    }];
}



#pragma mark - setter & getter

- (void)setDailyGatheringList:(NSArray<TGatheringDayModel *> *)dailyGatheringList {
    _dailyGatheringList = dailyGatheringList;
    
    CGFloat totalMoney = [TGatheringDayDAL getTotalDailyMoneyWithGatheringList:_dailyGatheringList];
    self.lblMoneyCommitValue.text = [NSString stringWithFormat:@"%.2f元", totalMoney];
    self.lblMoneySaleValue.text = [NSString stringWithFormat:@"%.2f元", totalMoney];
}








@end
